<?php
class Default_Forms_RegisterForm extends Zend_Form {
	function __construct($options = array()) {
		$this->setAction('')
				->setMethod('POST')
				->setAttrib('class','form-horizontal');
		$user_name = $this->createElement('text', 'username');
		$user_name->addValidator ( 'regex', false, array ('/^[a-z0-9_-]{3,20}$/','messages' =>
                                      array(Zend_Validate_Regex::NOT_MATCH => 'Tài khoản chỉ được chứa chữ, số và dấu gạch dưới')))
		            ->addValidator ( 'stringLength', false, array (3, 20 ) )
		            ->setRequired ( true )
		            ->addFilter ( 'StringToLower' )
		            ->addFilter('StringTrim')
		            ->setLabel('Tài khoản')
		            ->setAttrib('class','form-control');
		$password = $this->createElement ( 'password', 'password' );
		$password->addValidator ( 'StringLength', false, array (6,'messages' =>
                                      array(Zend_Validate_StringLength::TOO_SHORT => 'Mật khẩu không được phép ít hơn 6 ký tự')) )
        	     ->setRequired ( true )
        	     ->setLabel('Mật khẩu')
        	     ->setDescription("Tối thiểu 6 ký tự")
        	     ->setAttrib('class','form-control');
		$re_password = $this->createElement ( 'password', 're_password' );
		$re_password->addValidator ( 'StringLength', false, array (6,'messages' =>
                                      array(Zend_Validate_StringLength::TOO_SHORT => 'Mật khẩu không được phép ít hơn 6 ký tự')) )
        	     ->setRequired ( true )
        	     ->setLabel('Nhập lại mật khẩu')
        	     ->setIgnore(TRUE)
        	     ->setAttrib('class','form-control')
        	     ->addValidator('identical', false, array('token'	=> "password","messages"	=> array(Zend_Validate_Identical::NOT_SAME	=> "Mật khẩu không trùng nhau")));
		$first_name = $this->createElement('text', 'first_name');
		$first_name->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setLabel('Họ')
		            ->setAttrib('class','form-control');
		$last_name = $this->createElement('text', 'last_name');
		$last_name->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setLabel('Tên')
		            ->setAttrib('class','form-control');
		$email = $this->createElement('text', 'email');
		$email->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setLabel('Email')
		            ->setAttrib('class','form-control')
		            ->addValidator('EmailAddress',false,array('messages'	=> array(Zend_Validate_EmailAddress::INVALID_FORMAT	=> "Email không đúng định dạng")));
		$submit = $this->createElement('submit','login',array ('label' => "Đăng ký" ,'class'	=>'btn btn-large'));
		$this->addElement($user_name)
				->addElement($password)
				->addElement($re_password)
				->addElement($first_name)
				->addElement($last_name)
				->addElement($email)
				->addElement($submit);
		$this->setDecorators(array('FormElements',array('HtmlTag',array('tag'	=> 'div','width'=>'100%')),'form'));
		$this->setElementDecorators(array(
										'ViewHelper',
										'Errors',
										'Description',
										array(	
											array('data'	=> 'HtmlTag'),
											array('tag'		=> 'div','class'	=> 'col-md-6')),
										array('label',
											array('class'	=> 'col-md-3 control-label')),
										array(
											array('row'	=> 'HtmlTag',),
											array('class'=>'form-group')
		        						)
									)
								);
		$submit->setDecorators(array(
								'ViewHelper',
								array(
									array('data'	=> 'HtmlTag'),
									array('tag'		=>	'div','class'	=> 'col-md-9 col-md-offset-3')
								),
								array(
									array('row'	=> 'HtmlTag'),
									array('tag'	=> 'div',"class"	=> "form-group"))
									));
	}
}